
  
public class School {  
    private List<Department> departments;  
  
    public School() {  
        departments = new ArrayList<>();  
    }  
  
    public void addDepartment(Department department) {  
        departments.add(department);  
    }  
  
    // Getters and other methods if needed  
}  
  
public class Department {  
    private String name;  
    private List<Instructor> instructors;  
    private List<Subject> subjects;  
  
    public Department(String name) {  
        this.name = name;  
        instructors = new ArrayList<>();  
        subjects = new ArrayList<>();  
    }  
  
    public void addInstructor(Instructor instructor) {  
        instructors.add(instructor);  
    }  
  
    public void addSubject(Subject subject) {  
        subjects.add(subject);  
    }  
  
    // Getters and other methods if needed  
}  
  
public class Instructor {  
    private String name;  
    private Department department;  
    private List<Subject> subjects;  
  
    public Instructor(String name, Department department) {  
        this.name = name;  
        this.department = department;  
        this.department.addInstructor(this); // Ensure bidirectional reference if needed  
        subjects = new ArrayList<>(3);  
    }  
  
    public void addSubject(Subject subject) {  
        if (subjects.size() < 3) {  
            subjects.add(subject);  
            subject.addInstructor(this); // Ensure bidirectional reference if needed  
        } else {  
            throw new IllegalStateException("Instructor cannot teach more than 3 subjects.");  
        }  
    }  
  
    // Getters and other methods if needed  
}  
  
public class Subject {  
    private String name;  
    private List<Instructor> instructors;  
  
    public Subject(String name) {  
        this.name = name;  
        instructors = new ArrayList<>();  
    }  
  
    public void addInstructor(Instructor instructor) {  
        instructors.add(instructor);  
    }  
  
    // Getters and other methods if needed  
}  
  
public class Student {  
    private String name;  
    private List<Subject> subjects;  
  
    public Student(String name) {  
        this.name = name;  
        subjects = new ArrayList<>(5);  
    }  
  
    public void enrollInSubject(Subject subject) {  
        if (subjects.size() < 5) {  
            subjects.add(subject);  
        } else {  
            throw new IllegalStateException("Student cannot enroll in more than 5 subjects.");  
        }  
    }  
  
    // Getters and other methods if needed  
}